package com.gr.staffpm.charts;

import java.io.Serializable;
import java.text.MessageFormat;

import org.jfree.chart.labels.AbstractXYItemLabelGenerator;
import org.jfree.chart.labels.XYToolTipGenerator;
import org.jfree.data.xy.XYDataset;
import org.jfree.util.PublicCloneable;


public class CreatedVsResolvedToolTipGenerator extends AbstractXYItemLabelGenerator implements XYToolTipGenerator,
        Cloneable, PublicCloneable, Serializable {

    private static final long serialVersionUID = 1L;

    /** The default tooltip format. */
    public final String formatString = "{0} {1} tasks";

    @Override
    public String generateToolTip(XYDataset dataset, int series, int item) {
        String result = null;
        Object[] items = createItemArray(dataset, series, item);
        result = MessageFormat.format(this.formatString, items);
        return result;
    }

    /**
     * Creates the array of items that can be passed to the 
     * {@link MessageFormat} class for creating labels.
     *
     * @param dataset  the dataset (<code>null</code> not permitted).
     * @param series  the series (zero-based index).
     * @param item  the item (zero-based index).
     *
     * @return An array of three items from the dataset formatted as
     *         <code>String</code> objects (never <code>null</code>).
     */
    @Override
    protected Object[] createItemArray(XYDataset dataset, int series, int item) {
        Object[] result = new Object[2];
        result[0] = dataset.getSeriesKey(series).toString();
        result[1] = dataset.getY(series, item);
        return result;
    }

}
